home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Format / asn / opt_cmdln.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  3.0 KB  |  166 lines

  1. /* opt_cmdln.c: sets the ASNCMD structure to the command line values */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Format/asn/RCS/opt_cmdln.c,v 6.0 1991/12/18 20:15:43 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Format/asn/RCS/opt_cmdln.c,v 6.0 1991/12/18 20:15:43 jpo Rel $
  9.  *
  10.  * $Log: opt_cmdln.c,v $
  11.  * Revision 6.0  1991/12/18  20:15:43  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18.  
  19. #include    "head.h"
  20. #include    "asn.h"
  21. #include    <isode/cmd_srch.h>
  22.  
  23.  
  24. extern char    *myname;
  25. int        MnemonicsRequired = FALSE;
  26. int        CRline = FALSE;
  27.  
  28.  
  29. /* -- command line option definitions -- */
  30. #define OPT_ISET    1    /* -- input character set -- */
  31. #define OPT_OSET    2    /* -- output character set -- */
  32. #define OPT_IASN    3    /* -- input asn coding used -- */
  33. #define OPT_OASN    4    /* -- output asn coding used -- */
  34. #define OPT_X408    5
  35. #define OPT_MNEMONICS    6
  36. #define OPT_CR        7
  37.  
  38.  
  39. static CMD_TABLE  tbl_cmdln[] = {/* -- command line options -- */
  40.     "-is",        OPT_ISET,
  41.     "-os",        OPT_OSET,
  42.     "-ia",        OPT_IASN,
  43.     "-oa",        OPT_OASN,
  44.     "-x",        OPT_X408,
  45.     "-m",        OPT_MNEMONICS,
  46.     "-l",        OPT_CR,
  47.     0,        -1
  48.     };
  49.  
  50.  
  51.  
  52.  
  53.  
  54. /* ------------------------  Start Routine  --------------------------------- */
  55.  
  56.  
  57.  
  58. opt_cmdln (opts, ap)
  59. char    **opts;
  60. ASNCMD    *ap;
  61. {
  62.  
  63.     int    retval;
  64.     char    *key;
  65.  
  66.     PP_NOTICE (("%s", myname));
  67.     
  68.     while(*opts != NULL) {
  69.         switch(cmd_srch(*opts, tbl_cmdln)) {
  70.         case OPT_ISET:
  71.             key = *opts;
  72.             opts++;
  73.             set_val (key, *opts, &ap -> in_charset); 
  74.             break;
  75.         case OPT_OSET:
  76.             key = *opts;
  77.             opts++;
  78.             set_val (key, *opts, &ap -> out_charset); 
  79.             break;
  80.         case OPT_IASN:
  81.             key = *opts;
  82.             opts++;
  83.             set_val (key, *opts, &ap -> in_asn.name);
  84.             break;
  85.         case OPT_OASN:
  86.             key = *opts;
  87.             opts++;
  88.             set_val (key, *opts, &ap -> out_asn.name);
  89.             break;
  90.         case OPT_X408:
  91.             MnemonicsRequired = FALSE;
  92.             break;
  93.         case OPT_MNEMONICS:
  94.             MnemonicsRequired = TRUE;
  95.             break;
  96.         case OPT_CR:
  97.             CRline = TRUE;
  98.             break;
  99.         default:
  100.             PP_LOG(LLOG_EXCEPTIONS, ("unknown option '%s'", *opts));
  101.             exit (1);    
  102.         }
  103.         opts++;
  104.     }
  105.  
  106.     cmdln_chks (ap);
  107. }
  108.  
  109.  
  110.  
  111.  
  112. /* ----------------------  Static  Routines  -------------------------------- */
  113.  
  114.  
  115.  
  116.  
  117. static cmdln_chks(ap)
  118. ASNCMD    *ap;
  119. {
  120.  
  121.     PP_TRACE (("cmdln_chks()"));
  122.  
  123.     if ((lexequ (ap -> in_charset, ap -> out_charset) == 0) &&
  124.        (lexequ (ap -> in_asn.name, ap -> out_asn.name) == 0)) {
  125.         PP_LOG(LLOG_EXCEPTIONS, ("Error: no conversion is required"));
  126.         exit (1);
  127.     }
  128.  
  129.     /* -- outchar then must specify inchar -- */
  130.     if ((ap -> out_charset) && (ap -> in_charset == NULLCP)) {
  131.         PP_LOG(LLOG_EXCEPTIONS, ("Error: inchar not specified"));
  132.         exit (1);
  133.     }
  134.  
  135.     /* -- inchar then must specify outchar -- */
  136.     if ((ap -> in_charset) && (ap -> out_charset == NULLCP)) {
  137.         PP_LOG(LLOG_EXCEPTIONS, ("Error: outchar not specified"));
  138.         exit (1);
  139.     }
  140.  
  141. }
  142.  
  143.  
  144.  
  145. static int set_val (key, val, base)
  146. char    *key;
  147. char    *val;
  148. char    **base;
  149. {
  150.  
  151.     PP_NOTICE (("\t%s='%s'", key, val));
  152.  
  153.  
  154.     if (val == NULLCP) {
  155.         PP_LOG(LLOG_EXCEPTIONS, ("Error: No value specified"));
  156.         exit (1);
  157.     }
  158.  
  159.     if (val[0] == '-') {
  160.         PP_LOG(LLOG_EXCEPTIONS, ("Error: Bad value '%s'", val));
  161.         exit (1);
  162.     }
  163.  
  164.     *base = strdup (val);
  165. }
  166.